package com.yanq.liancar.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.vondear.rxtool.view.RxToast;
import com.yanq.liancar.R;
import com.yanq.liancar.bean.BaseUserInfo;
import com.yanq.liancar.bean.GetUIdBean;
import com.yanq.liancar.bean.MileageBBean;
import com.yanq.liancar.bean.MileageBean;
import com.yanq.liancar.bean.OdbCheckOilWearBean;
import com.yanq.liancar.bean.UserBean;
import com.yanq.liancar.url.Config;
import com.yanq.liancar.util.Utils;

import org.json.JSONArray;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OilFenxiActivity extends AppCompatActivity {

    @BindView(R.id.back_btn)
    ImageView backBtn;
    @BindView(R.id.tv)
    TextView tv;
    @BindView(R.id.oil_fenXi_time)
    TextView oil_fenXi_time;
    @BindView(R.id.oil_fenXi_chepai)
    TextView oil_fenXi_chepai;
    @BindView(R.id.oil_fenXi_tvA)
    TextView oilFenXiTvA;
    @BindView(R.id.oil_fenXi_tvB)
    TextView oilFenXiTvB;
    @BindView(R.id.oil_fenXi_tvC)
    TextView oilFenXiTvC;
    @BindView(R.id.oil_fenXi_tvBB)
    TextView oilFenXiTvBB;
    @BindView(R.id.oil_fenXi_tvCC)
    TextView oilFenXiTvCC;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_oil_fenxi);
        ButterKnife.bind(this);
        Utils.setStatusBar(this, false, true);
        findViewById(R.id.back_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        initUserInfo();
    }


    private void initUserInfo() {
        OkGo.<String>get(Config.s + "llc/odbcheck/odbCheckOilWear")
                .tag(this)
                .params("token", UserBean.getcToken(this))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Gson gson = new Gson();
                        OdbCheckOilWearBean info = gson.fromJson(response.body(), OdbCheckOilWearBean.class);
                        if (info.isIsSuccess()) {
                            oilFenXiTvA.setText(info.getData().getMile()+"");//里程
                            oilFenXiTvB.setText(info.getData().getLongTime()+"");//耗时
                            oilFenXiTvC.setText(info.getData().getFuelConsumption()+"");//油耗
                            oilFenXiTvBB.setText(info.getData().getAvgFuelConsumption()+"");//本次平均油耗
                            oilFenXiTvCC.setText(info.getData().getOilWear()+"");//历史油耗
//                            oilFenXiTvAA.setText();   //同车型平均油耗
                        } else {
                            RxToast.error(info.getOutputMessage());
                        }
                    }
                });
    }

}
